package com.second.app.callable;

/**
 * @Author GYZ
 * <pre>
 *
 * </pre>
 */
public class CallableDemo {

    public static void main(String[] args) {

        Thread thread1 = new Thread(new MyTask(), "窗口A");
        Thread thread2 = new Thread(new MyTask(), "窗口B");
        Thread thread3 = new Thread(new MyTask(), "窗口C");
        thread1.start();
        thread2.start();
        thread3.start();
        System.out.println("开始卖票啦@！:");
    }
}

class MyTask implements Runnable {

    private int ticketsCount = 20;

    @Override
    public void run() {
        while (true) {
            if (ticketsCount > 0) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "正在出售第" + ticketsCount + "张票");
                ticketsCount--;
            }
        }
    }
}
